/*
day96
2019.12.2
*/
#include<iostream>
#include<stdlib.h>
#define n 10

using namespace std;

struct sortNode {
	int val;
}; 

void fastSort(struct sortNode table[],int begin,int end)
{
	if(begin>=end) return ;
	
	int head=begin,tail=end;
	
	struct sortNode tem = table[head];
	while(tail>head)
	{
		
		while(tail>head && table[tail].val>=tem.val) 
		{
			tail--;
		}
		table[head]=table[tail];
		
		while(tail>head && table[head].val<=tem.val) 
		{
			head++;
		}
		table[tail]=table[head];
	}
	table[head]=tem;
	
	fastSort(table,begin,head-1);
	fastSort(table,head+1,end);
	
}



void showTable(struct sortNode table[])
{
	for(int i=0;i<n;i++)
	{
		cout<<table[i].val<<'\t';
	}
}


int main()
{
	struct sortNode table[n];
	for(int i=0;i<n;i++)
	{
		table[i].val=rand();
	}
	showTable(table);
	cout<<endl;
 
	fastSort(table,0,n-1);
	cout<<endl<<endl;
	showTable(table);
	return 0;
}
